package com.ushine.design.design.a_creative_mode.f_single;


import com.ushine.design.design.a_creative_mode.f_single.a_basic.Singleton;
import com.ushine.design.design.a_creative_mode.f_single.b_eager.EagerSingleton;
import com.ushine.design.design.a_creative_mode.f_single.c_lazy.LazySingleton;

public class Client {
    public static void main(String[] args) {
        /**
         * 基本的单例模式
         */
        Singleton singleton1 = Singleton.getInstance();
        Singleton singleton2 = Singleton.getInstance();
        if (singleton1 == singleton2) {
            System.err.println(singleton1);
            System.err.println(singleton2);
            System.out.println("两个相同的实例。");
        } else {
            System.out.println("完全不同的两个实例。");
        }


        /**
         * 懒汉单例模式
         */
        EagerSingleton eSingleton1 = EagerSingleton.getInstance();
        EagerSingleton eSingleton2 = EagerSingleton.getInstance();
        if (eSingleton1 == eSingleton2) {
            System.err.println(eSingleton1);
            System.err.println(eSingleton2);
            System.out.println("两个相同的实例。");
        } else {
            System.out.println("完全不同的两个实例。");
        }

        /**
         * 一重锁检查机制
         */
        LazySingleton lazySingleton1 = LazySingleton.getInstance();
        LazySingleton lazySingleton2 = LazySingleton.getInstance();
        if (lazySingleton1 == lazySingleton2) {
            System.err.println(lazySingleton1);
            System.err.println(lazySingleton2);
            System.out.println("两个相同的实例。");
        } else {
            System.out.println("完全不同的两个实例。");
        }


        /**
         * 双重锁检查机制
         */
        LazySingleton instanceByTwoLock1 = LazySingleton.getInstanceByTwoLock();
        LazySingleton instanceByTwoLock2 = LazySingleton.getInstanceByTwoLock();
        if (instanceByTwoLock1 == instanceByTwoLock2) {
            System.err.println(instanceByTwoLock1);
            System.err.println(instanceByTwoLock2);
            System.out.println("两个相同的实例。");
        } else {
            System.out.println("完全不同的两个实例。");
        }

    }
}
